home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15648 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  36 lines

  1. Newsgroups: comp.lang.c++
  2. Path: presby.edu!jtbell
  3. From: jtbell@presby.edu (Jon Bell)
  4. Subject: Re: Operator Overloading
  5. Message-ID: <DpIDqG.64M@presby.edu>
  6. Date: Sun, 7 Apr 1996 20:18:15 GMT
  7. References: <9604071905.AA001o6@lorelei.demon.co.uk>
  8. Organization: Presbyterian College, Clinton, South Carolina USA
  9.  
  10.  John Croudy  <john@lorelei.demon.co.uk> wrote:
  11. >I then tried this:
  12. >
  13. >       class MyClass
  14. >       ...
  15. >       operator double () const { return something; }
  16. >       ...
  17. >
  18. >and it seems to allow me to say
  19. >
  20. >       double x;
  21. >
  22. >       x = MyClass;
  23. >
  24. >It seems to be a user-defined casting operator, but I can't find any
  25. >mention of this in any books I have.  Can anyone explain what I have
  26. >discovered here?
  27.  
  28. That's exactly what it is:  a user-defined conversion (cast) from type
  29. 'MyClass' to type 'double'.  See, for example, Lippman's "C++ Primer"
  30. (published by Addison-Wesley), which should be available in most good
  31. bookstores. 
  32.  
  33. -- 
  34. Jon Bell <jtbell@presby.edu>                        Presbyterian College
  35. Dept. of Physics and Computer Science        Clinton, South Carolina USA
  36.